package ink.lovejinhu.leetcode;

import ink.lovejinhu.common.ListNode;

import java.util.Stack;

/**
 * @author jinhu
 * created 2021-07-09 9:09
 */
public class Solution_0234 {
    /**
     * 回文链表
     *
     * @param head
     * @return
     */
    public boolean isPalindrome(ListNode head) {
        if (head == null) {
            return true;
        }
        ListNode temp = head;
        Stack<ListNode> listNodes = new Stack<>();
        while (temp != null) {
            listNodes.push(temp);
            temp = temp.next;
        }
        while (head != null) {
            if (head.val != listNodes.pop().val) {   //只需要值相等
                return false;
            }
            head = head.next;
        }
        return true;
    }
}
